﻿using System;

namespace 第三次课堂作业
{
	class Program
	{
		public void getArea(double x,double y)
		{
			if (x > 0 && y > 0)
			{
				if (x == y)
				{
					Console.WriteLine("这是一个正方形，面积是：");
				}
				else
				{
					Console.WriteLine("这是一个长方形，面积是：");
				}
				Console.WriteLine(2 * (x + y));
			}
			else
			{
				Console.WriteLine("这不是一个合法的图形,长宽分别为：");
				Console.WriteLine(x+"  "+y);
			}
				
		}
		
		public void getArea(double a,double b,double c)
		{
			if (a > 0 && b > 0 && c > 0 && a + b > c && a - b < c)
			{
				double p = (a + b + c) / 2.0;
				Console.WriteLine("这是一个三角形,面积为：");
				Console.WriteLine(Math.Sqrt(p * (p - a) * (p - b) * (p - c)));
			}
			else
			{
				Console.WriteLine("这不是一个合法的三角形，三边长为：");
				Console.WriteLine(a+"  "+b+"  "+c);
			}
			
		}
		static void Main(string[] args)
		{
			Program p = new Program();
			Random r = new Random();
			for(int i = 0; i < 10; i++)
			{
				int shape = r.Next(2, 4);
				Random x = new Random();
				Random y = new Random();
				switch (shape)
				{
					case 2:
						double width = x.Next(10) -5 + y.NextDouble();
						double height = x.Next(10) - 5 + y.NextDouble();
						p.getArea(width,height);
						break;
					case 3:
						double a = x.Next(10) - 5 + y.NextDouble();
						double b = x.Next(10) - 5 + y.NextDouble();
						double c = x.Next(10) - 5 + y.NextDouble();
						p.getArea(a, b, c);
						break;
					default:
						break;

				}
			}
			
		}
	}
}
